<template>
  <div :class="{'has-logo':showLogo}">
    <logo v-if="showLogo" :collapse="isCollapse"/>
    <el-scrollbar :style="`margin-top:${showLogo?'50px' : 0}`" class="sidebar-container" wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="variables.menuBg"
        :text-color="variables.menuText"
        :unique-opened="false"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false">
        <el-menu-item index="home" @click="$router.push({ name: 'home' })">
          <icon-svg name="dashboard" class="svg-icon"></icon-svg>
          <span slot="title">首页</span>
        </el-menu-item>
        <sidebarItem v-for="menu in menuList" :key="menu.menuId" :menu="menu" :dynamicMenuRoutes="dynamicMenuRoutes">
        </sidebarItem>
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import sidebarItem from '@/views/main/components/Sidebar/SidebarItem'
import Logo from './Logo'
import { mapGetters } from 'vuex'
import variables from '@/styles/variables.scss'

// import { validURL } from '@/utils/validate'

export default {
  data () {
    return {
      dynamicMenuRoutes: [],
      menuList: []
    }
  },
  components: {
    sidebarItem,
    Logo
  },
  computed: {
    ...mapGetters([
      'sidebar'
    ]),
    activeMenu () {
      const route = this.$route
      const { meta, name } = route

      return String(meta.menuId || name)
    },
    showLogo () {
      return this.$store.state.settings.sidebarLogo
    },
    variables () {
      return variables
    },
    isCollapse () {
      return !this.sidebar.opened
    }
  },
  watch: {},
  created () {
    this.dynamicMenuRoutes = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]')
    this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]')
  },
  methods: {}
}
</script>
